package com.xjtu.platform.security.modifypassword.impl;

import com.xjtu.platform.common.Constants;
import com.xjtu.platform.security.avator.dao.AvatarDao;
import com.xjtu.platform.security.modifypassword.ModifyPasswordDto;
import com.xjtu.platform.security.modifypassword.ModifyPasswordService;
import com.xjtu.platform.security.modifypassword.dao.ModifyPasswordDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
@Transactional
public class ModifyPasswordServiceImpl implements ModifyPasswordService{
    @Resource
    private ModifyPasswordDao dao;
    @Override
    public Integer upDatePassword(ModifyPasswordDto dto) {
        System.out.println(dto.getOldPassword());
        if(dto.getOldPassword()==null||!dto.getOldPassword().equals(dao.searchPwdById(dto)))
        {
            return Constants.WRONG_PASSWORD;
        }
        if(!checkPwd(dto.getUser_pwd()))
        {
            return Constants.INVALID_NEW_PASSWORD;
        }
        dao.modifyPasswordById(dto);
        return Constants.SUCCESS_MODIFY_PASSWORD;
    }

    private boolean checkPwd(String newPassword) {
        if(newPassword.length()<6)
        {
            return false;
        }
        return true;
    }
}
